/*
 * Vector.h
 *
 *  Created on: May 26, 2011
 *      Author: gilang
 */

#ifndef VECTOR_H_
#define VECTOR_H_

class Vector {
private:
	double *values;
	int row;
public:
	Vector() {
	}
	Vector(int b) {
		row = b;
		values = new double[b + 1];
	}
	int getRow() {
		return row;
	}
	void set(int i, double t) {
		values[i] = t;
	}
	double & operator()(int i) {
		return values[i];
	}
	Vector operator+(const Vector &v) {
		Vector z = Vector(v.row);
		for (int i = 1; i <= z.row; i++)
			z.values[i] = values[i] + v.values[i];
		return z;
	}

	Vector & operator+=(const Vector &v) {
		for (int j = 1; j <= row; j++) {
			values[j] += v.values[j];
		}
		return *this;
	}
	Vector operator-(const Vector &v) {
		Vector z = Vector(v.row);
		for (int i = 1; i <= z.row; i++)
			z.values[i] = values[i] - v.values[i];
		return z;
	}
	Vector operator*(const double &t) {
		for (int i = 1; i <= row; i++)
			values[i] = t * values[i];
		return *this;
	}

	Vector operator=(const Vector &v) {
		row = v.row;
		values = v.values;
		return *this;
	}

	static Vector copyValueOf(Vector &v) {
		Vector vc = Vector(v.row);
		vc += v;
		return vc;
	}

	double * getValues() {
		return values;
	}
	virtual ~Vector() {
	}
};

#endif /* VEC OR_H_ */
